<template>
  <view class="">
    <!-- <view class="category-container" :class="customTabbar && isIpx ? 'custom-tab-bottom-ipx' : customTabbar && !isIpx ? 'custom-tab-bottom' : ''">
      <tabBar v-if="customTabbar === 1 && tabbarTimeout" :nowPages.sync="nowPages"></tabBar>
      <navBar v-if="isShowCustomNavBar" :navbarData.sync="navbarData"></navBar>
      <onlineService></onlineService>
      <category ref="category" id="refCategory" @categoryChange="categoryChange" :categoryFixed.sync="categoryFixed"
        :isCateScroll.sync="isCateScroll" :changeCate.sync="changeCate"></category>
      <newCategory ref="newCategoryRef" id="refNewCategory"></newCategory>
    </view> -->
    <!-- <loading :showLoaded.sync="showLoaded"></loading> -->
  </view>

</template>

<script>
  import api from '@/api/api';
  import tip from '@/utils/tip';
  import TabBar from '@/components/common/tabbar';
  import {
    CART_KEY,
    SYSTEM_INFO,
    USER_SPECICAL_INFO,
    MERCHANT_INFO,
    CUSTOMER_INFO,
    LOWER_WX_VERSION
  } from '@/utils/constant';
  import NavBar from '@/components/common/navbar';
  import onlineService from '@/components/common/onlineService';
  // import category from '@/components/category/category';
  // import newCategory from '@/components/newCategory/newCategory';
  export default {
    config: {
      navigationBarTitleText: '搜索',
      navigationStyle: 'custom'
    },
    components: {
      navBar: NavBar,
      onlineService: onlineService,
      // category: category,
      tabBar: TabBar,
      // newCategory: newCategory
    },
    data() {
      return {
        showLoaded: true,
        forceRefresh: false,
        customTabbar: -1,
        navbarData: {
          showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
          navbarTitle: '',
        },
        isShowCustomNavBar: true,
        type: 'category', // category/search
        categoryFixed: 0,
        isCateScroll: false,
        changeCate: 0,
        // 商户id
        merchantId: '',
        storeId: '',
        isSort: 1, //是否显示排序           0显示 1不显示
        isFilter: '', //是否显示筛选          0 不显示 1 显示
        isAppend: 0, // 是否显示悬浮图    0 不显示 1 显示

        // 品牌信息 0：三仟院  1：ICH  2:PB
        brandType: getApp().globalData.brandType,
        memberLevelId: 0,
        customerGroupId: 0,
        nowPages: '',
        isIpx: getApp().globalData.isIpx,
        tabbarTimeout: false,
        thridTop: 0
      };
    },

    onLoad() {

    },
    onShow() {
      let that = this
      setTimeout(() => {
        that.tabbarTimeout = true;
      }, 1000)
      let memberDetails = uni.getStorageSync('memberDetails');
      this.memberLevelId = memberDetails.memberLevelId || 0;
      let customerInfo = uni.getStorageSync('customerInfo');
      this.customerGroupId = customerInfo.groupId || 0;
      //解决占用内存过多而导致page reload发生
      let page = getCurrentPages();
      getApp().cl_tracker.track('mini_program_view', {
        path: this.nowPages,
        pageName: '酒窖',
      });
      const query = uni.createSelectorQuery().in(that);
      query.select('#refCategory').boundingClientRect()
      query.selectViewport().scrollOffset()
      query.exec(function(res) {
        if (page[0].__displayReporter.showReferpagepath == 'pages/GTR/item.html' && res[1].scrollTop == 0) {
          that.categoryFixed = 0;
          that.isCateScroll = true;
          that.changeCate = 2;
        }
      })
      setTimeout(() => {
        const thirdTop = uni.createSelectorQuery().in(that);
        thirdTop.select('#cateItem2').boundingClientRect()
        thirdTop.selectViewport().scrollOffset()
        thirdTop.exec(function(res) {
          that.thridTop = res[1].scrollHeight - 1060
        })
      }, 1300)
    },
    //点击酒窖tabber埋点
    onTabItemTap(e) {
      let text = e.text
      let clTrackPrams = {
        'c_tab': "酒窖",
        'c_link_pagename': e.text,
        'c_link_path': e.pagePath
      }
      getApp().commonClTrack('c_ebmp_click_tabbar', clTrackPrams)
    },
    methods: {
      // 切换分类
      categoryChange(val) {
        
      },


      // 判断是否有merchantInfo,没有则重新请求
      getCurrentMerchantInfo: async function() {
        let that = this;
        var merchantInfo = uni.getStorageSync(MERCHANT_INFO) || '';
        this.merchantId = uni.getStorageSync(MERCHANT_INFO).cloudMerchantId || '';
        this.storeId = uni.getStorageSync(MERCHANT_INFO).cloudMerchantStoreId || '';
        if (merchantInfo) {
          this.show = false;
          this.$refs.category.getRootCateTopLevel(this.storeId)
        } else {
          // 获取商户信息
          const accountInfo = uni.getAccountInfoSync(); // 小程序appId
          var merchantInfo = await api.merchantInfo(accountInfo.miniProgram.appId);
          if (merchantInfo.code === 200) {
            // 存储商户信息
            uni.setStorageSync(MERCHANT_INFO, merchantInfo.data);
            that.storeId = merchantInfo.data.cloudMerchantStoreId;
            that.merchantId = merchantInfo.data.cloudMerchantId;
            this.show = false;
            this.$refs.category.getRootCateTopLevel(this.storeId)
          }
        }
      },

    },
    //加载更多
    onReachBottom() {
      let that = this;
    },

    /**
     * 监听页面滑动事件
     */
    onPageScroll: function(Object) {
      var that = this;
      // let thirdTop = api.environment == 'trial' ? 680 : 2140
      let thirdTop = this.thridTop
      if (Object.scrollTop > 200) { //分类悬浮
        this.categoryFixed = 1;
      } else {
        this.categoryFixed = 0;
      }
      if (Object.scrollTop < 480) { //分类悬浮
        this.changeCate = 0;
      } else if (Object.scrollTop > 480 && Object.scrollTop < thirdTop) {
        this.changeCate = 1;
      } else if (Object.scrollTop > thirdTop) { //分类悬浮
        this.changeCate = 2;
      }
      // this.$refs.category.pageScroll(Object)
      if (Object.scrollTop > 0) {
        this.isCateScroll = true;
      } else {
        this.isCateScroll = false;
      }
    }
  }
</script>

<style lang="less">

</style>